package org.trackcore.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.trackcore.common.BaseResponse;
import org.trackcore.common.ResultUtils;
import org.trackcore.model.entity.BaseLog;
import org.trackcore.service.BaseLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.annotation.Resource;

@RestController
@RequestMapping("/log")
@Api(tags = "基础日志")
public class BaseLogController {

    @Resource
    private BaseLogService baseLogService;

    /**
     * 分页查询所有日志
     * @param pageNum 当前页码
     * @param pageSize 每页条数
     */
    @GetMapping("/list")
    @ApiOperation("分页查询所有日志")
    public BaseResponse<IPage<BaseLog>> listAllLogs(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<BaseLog> page = new Page<>(pageNum, pageSize);
        IPage<BaseLog> logPage = baseLogService.page(page);
        return ResultUtils.success(logPage);
    }

/*    *//**
     * 按条件查询日志
     * @param log 包含查询条件的日志对象
     * @param pageNum 当前页码
     * @param pageSize 每页条数
     *//*
    @PostMapping("/query")
    public BaseResponse<IPage<BaseLog>> queryLogs(
            @RequestBody BaseLog log,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<BaseLog> page = new Page<>(pageNum, pageSize);
        IPage<BaseLog> result = baseLogService.queryByCondition(page, log);
        return ResultUtils.success(result);
    }*/

    /**
     * 获取日志详情
     * @param id 日志ID
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("获取日志详情")
    public BaseResponse<BaseLog> getLogDetail(@PathVariable String id) {
        BaseLog log = baseLogService.getById(id);
        return ResultUtils.success(log);
    }
}